package com.kexinde.wjifen.util;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
/**
 * ��ҳ����
 * @author vincent
 *
 */
@Component("pageManager")
public class PageManager {
	private Page pageDAO;
	private int amount;
	public Page getPageDAO() {
		return pageDAO;
	}

	@Resource
	public void setPageDAO(Page pageDAO) {
		this.pageDAO = pageDAO;
	}
	
	public int getPageAmount(String table,int lineSize){
		amount=pageDAO.countRecord(table);
		if(amount%lineSize!=0)
		return amount/lineSize+1;
		else
			return amount/lineSize;
	}
	
	public List<Object> doPageList(String table, int currentPage, int lineSize) {
		int pageAmount = this.getPageAmount(table, lineSize);
		int first=(currentPage-1)*lineSize;
		if (currentPage != pageAmount) {
			int max = lineSize;
			return pageDAO.pageList(first, max, table);
		}
		else{
			int max=amount-(currentPage-1)*lineSize;
			return pageDAO.pageList(first, max, table);
		}

	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

}
